import numpy as np

A = np.arange(2, 14).reshape((3, 4))

# array([[ 2, 3, 4, 5]
#        [ 6, 7, 8, 9]
#        [10,11,12,13]])

print(np.argmin(A))  # 0
print(np.argmax(A))  # 11
print(np.mean(A))  # 7.5
print(np.average(A))  # 7.5
print(A.mean())  # 7.5
print(A.median())  # 7.5 中位数
print(np.cumsum(A))  # [2 5 9 14 20 27 35 44 54 65 77 90]
print(np.diff(A))
# [[1 1 1]
#  [1 1 1]
#  [1 1 1]]
print(np.nonzero(A))  # 这个函数将所有非零元素的行与列坐标分割开，重构成两个分别关于行和列的矩阵。
# (array([0,0,0,0,1,1,1,1,2,2,2,2]),array([0,1,2,3,0,1,2,3,0,1,2,3]))
A = np.arange(14, 2, -1).reshape((3, 4))
# array([[14, 13, 12, 11],
#       [10,  9,  8,  7],
#       [ 6,  5,  4,  3]])
print(np.sort(A))
# array([[11,12,13,14]
#        [ 7, 8, 9,10]
#        [ 3, 4, 5, 6]])

# 矩阵的转置有两种表示方法
print(np.transpose(A))
print(A.T)

# array([[14,10, 6]
#        [13, 9, 5]
#        [12, 8, 4]
#        [11, 7, 3]])
# array([[14,10, 6]
#        [13, 9, 5]
#        [12, 8, 4]
#        [11, 7, 3]])
print(np.clip(A, 5, 9))
# array([[ 9, 9, 9, 9]
#        [ 9, 9, 8, 7]
#        [ 6, 5, 5, 5]])
